<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;
use app\common\model\Kouling as KoulingModel;

class Kouling extends AdminBase
{
    protected $kouling_model;
    protected function _initialize()
    {
        $this->kouling_model = new KoulingModel;
        parent::_initialize();
    }

    public function index(){
        $result = $this->kouling_model->where('status',1)->select();
        $this->assign('kouling_list',$result);
        return $this->fetch();
    }

    public function add(){
        return $this->fetch();
    }

    public function save(){
        if($this->request->isPost()){
            $data = $this->request->param();
            $result = $this->kouling_model->allowField(true)->save($data);
            if($result){
                $this->success('保存成功');
            }else{
                $this->error('保存失败');
            }
        }
    }

    public function edit($id){
        $result = $this->kouling_model->where('id',$id)->find();
        $this->assign('kouling',$result);
        return $this->fetch();
    }

    public function update($id){
        if($this->request->isPost()){
            $data = $this->request->param();
            $result = $this->kouling_model->allowField(true)->save($data,['id'=>$id]);
            if($result){
                $this->success('修改成功');
            }else{
                $this->error('修改失败');
            }
        }
    }

    public function delete($id){
        $data = ['status'=>0];
        $result = $this->kouling_model->allowField(true)->save($data,['id'=>$id]);
        if($result){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }
}